home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / programm.ing / falcon / a56v12st.lzh / a56 / examples / x.a56 < prev    next >
Encoding:
Text File  |  1994-09-02  |  10.2 KB  |  589 lines

  1. ;***************************************************************
  2. ; A stereo reverb for the DSP56001 signal processor.  Based on,
  3. ;    Moorer, James A. "About This Reverberation Business."
  4. ;    Computer Music Journal Vol 3, No. 2 (1979), pp. 13-28.
  5. ;
  6. ;   reprinted in,
  7. ;
  8. ;    Roads, Curtis, and Strawn, John, ed., _Foundations
  9. ;    of Computer Music_, pp. 605-639, MIT Press, 1985.
  10. ;    ISBN 0-262-68051-3 (paper)
  11. ;    ISBN 0-262-181142 (hard)
  12. ;
  13. ; Each comb filter uses a low-pass filter in the feedback path.
  14. ; The combs and all-pass filter delay lines use a prime-number
  15. ; of stages to improve diffusion.
  16. ;
  17. ; The output all-pass stage is replicated for left/right
  18. ; decorrelation.  Each side uses slightly different gains
  19. ; and delay lengths.  This works a lot better than just inverting
  20. ; one side and adding in the input.
  21. ;
  22. ; I left out the early-reflection FIR filter because I needed the cycles
  23. ; for other effects.
  24. ;
  25. ; Quinn Jensen (jensenq@qcj.icon.com)
  26. ;
  27. ;***************************************************************
  28.     psect    vectors        p:$0000:$0040
  29.     psect    hf_code        p:$0040:$0200
  30.     psect    hf_datax    x:$0000:$0040
  31.     psect    hf_datax1    x:$0040:$0100
  32.     psect    hf_datay    y:$0000:$0040
  33.     psect    hf_datay1    y:$0040:$0100
  34.     psect    midi_data    x:$0400:$1000
  35.     psect    lo_data        x:$1000:$F000
  36.     psect    lo_code        p:$F000:$FE00
  37.     psect    loader        p:$FE00:$FFFF
  38.     psect    iox        x:$FFC0:$FFFF
  39.     psect    ioy        y:$FFC0:$FFFF
  40. ;
  41. ; some oft-used constants
  42. ;
  43.     psect    hf_datax
  44. ffff    dc    $FFFF        ;used a lot for modulus
  45. ONE    equ    $7FFFFF        ;"one"
  46. one    dc    ONE        ;"one"
  47. ;
  48. ; L/R inputs and outputs
  49. ;
  50. in_l    dc    0.0      
  51. in_r    dc    0.0      
  52. out_l    dc    0.0      
  53. out_r    dc    0.0      
  54. ;
  55. ; recompute comb gains g1 and g2
  56. ;
  57. recalc_comb_gains
  58.     move        x:<constsp,r0
  59.     movec        x:<ffff,m0
  60.     move        x:lowpass_cutoff_start,b
  61.     move        x:lowpass_cutoff_slope,y1
  62.     move        x:comb_g,x1
  63.     move        #0.5,x0
  64.  
  65.     do    #6,recalc_loop
  66.       clr    a    (r0)+        ;skip over the modulus const
  67.       add    x0,a    b,y0
  68.       mac    x0,y0,a            ;g1 = .5 * b + .5
  69.       clr    a    a,y0        ;y0 = g1
  70.       add    x1,a    y0,y:(r0)+    ;store g1 in table
  71.       macr    -x1,y0,a        ;g2 = g(1-g1) = g - g*g1 with limiting
  72.       add    y1,b    a,y:(r0)+    ;update b, store g2 in table
  73. recalc_loop
  74.     rts
  75.  
  76.     psect    midi_data
  77. ;
  78. ; default values for midi-derived parameters
  79. ;
  80. lowpass_cutoff_start
  81.     dc    -0.3906250    ; ctl value of 39
  82. lowpass_cutoff_slope
  83.     dc    0.0468750    ; ctl value of 67
  84. comb_g
  85.     dc    0.8325507974    ; ctl value of 57
  86. ;
  87. ; preset comb-length arrays
  88. ;
  89.  
  90.  
  91.  
  92. ; comb lenths 383,433,467,523,557,601
  93. comblen_1
  94.     dc    383-1
  95.     dc    433-1
  96.     dc    467-1
  97.     dc    523-1
  98.     dc    557-1
  99.     dc    601-1
  100.  
  101.  
  102. ; comb lenths 509,577,631,701,743,797
  103. comblen_2
  104.     dc    509-1
  105.     dc    577-1
  106.     dc    631-1
  107.     dc    701-1
  108.     dc    743-1
  109.     dc    797-1
  110.  
  111.  
  112. ; comb lenths 683,769,839,937,991,1069
  113. comblen_3
  114.     dc    683-1
  115.     dc    769-1
  116.     dc    839-1
  117.     dc    937-1
  118.     dc    991-1
  119.     dc    1069-1
  120.  
  121.  
  122. ; comb lenths 919,1021,1117,1249,1319,1427
  123. comblen_4
  124.     dc    919-1
  125.     dc    1021-1
  126.     dc    1117-1
  127.     dc    1249-1
  128.     dc    1319-1
  129.     dc    1427-1
  130.  
  131.  
  132. ; comb lenths 1223,1367,1489,1657,1759,1901
  133. comblen_5
  134.     dc    1223-1
  135.     dc    1367-1
  136.     dc    1489-1
  137.     dc    1657-1
  138.     dc    1759-1
  139.     dc    1901-1
  140.  
  141.  
  142. ; comb lenths 1627,1823,1987,2213,2341,2539
  143. comblen_6
  144.     dc    1627-1
  145.     dc    1823-1
  146.     dc    1987-1
  147.     dc    2213-1
  148.     dc    2341-1
  149.     dc    2539-1
  150.  
  151.  
  152. ;;;;;;;;;;;;;;;;;;;;;;;
  153. ; reverb filters
  154. ;;;;;;;;;;;;;;;;;;;;;;;
  155.  
  156. ;  Reverb filter lengths and coefficients     
  157. ;  6 comb reverb with prime delay lines
  158. ;  Sun Oct 24 13:53:51 1993
  159. ;  
  160. ;                          Sample rate        32.5520830 kHz      
  161. ;                          g                   0.8400000
  162. ;  
  163. ;                    status      STABLE       
  164. ;         delay      near prime lengths actual
  165. ;  stage   (ms)   1  high   low  best  delay        g1        g2
  166. ;  ---------------------------------------------------------------
  167. ;  Comb 1  50.0  1628  1637  1627  1627 49.981 0.3064583 0.5825750
  168. ;  Comb 2  56.0  1823  1823  1823  1823 56.003 0.3264583 0.5657750
  169. ;  Comb 3  61.0  1986  1987  1979  1987 61.041 0.3464583 0.5489750
  170. ;  Comb 4  68.0  2214  2221  2213  2213 67.983 0.3594792 0.5380375
  171. ;  Comb 5  72.0  2344  2347  2341  2341 71.916 0.3694792 0.5296375
  172. ;  Comb 6  78.0  2539  2539  2539  2539 77.998 0.4243750 0.4835250
  173. ;  All      6.0   195   197   193   193  5.929 0.7000000
  174.  
  175. ; COMB(name, length, modulus, g1, g2)
  176.  
  177.  
  178.  
  179.  
  180. ; storage for "c1" length=1627 modulus=2048 g1=0.3046875 g2=0.5812382
  181.  
  182.     psect    lo_data
  183.     align    2048
  184. c1d
  185. c1m    equ    1627-1
  186.     org    x:c1d+c1m
  187.     psect    hf_datax
  188. c1g1    equ    0.3046875
  189. c1g2    equ    0.5812382
  190.  
  191.  
  192. ; storage for "a1" length=193 modulus=256 g1=0.7000000 g2=0.0000000
  193.  
  194.     psect    lo_data
  195.     align    256
  196. a1d
  197. a1m    equ    193-1
  198.     org    x:a1d+a1m
  199.     psect    hf_datax
  200. a1g1    equ    0.7000000
  201. a1g2    equ    0.0000000
  202.  
  203.  
  204. ; storage for "c2" length=1823 modulus=2048 g1=0.3281250 g2=0.5616459
  205.  
  206.     psect    lo_data
  207.     align    2048
  208. c2d
  209. c2m    equ    1823-1
  210.     org    x:c2d+c2m
  211.     psect    hf_datax
  212. c2g1    equ    0.3281250
  213. c2g2    equ    0.5616459
  214.  
  215.  
  216. ; storage for "c3" length=1987 modulus=2048 g1=0.3515625 g2=0.5420536
  217.  
  218.     psect    lo_data
  219.     align    2048
  220. c3d
  221. c3m    equ    1987-1
  222.     org    x:c3d+c3m
  223.     psect    hf_datax
  224. c3g1    equ    0.3515625
  225. c3g2    equ    0.5420536
  226.  
  227.  
  228. ; storage for "c4" length=2213 modulus=4096 g1=0.3750000 g2=0.5224613
  229.  
  230.     psect    lo_data
  231.     align    4096
  232. c4d
  233. c4m    equ    2213-1
  234.     org    x:c4d+c4m
  235.     psect    hf_datax
  236. c4g1    equ    0.3750000
  237. c4g2    equ    0.5224613
  238.  
  239.  
  240. ; storage for "a2" length=207 modulus=256 g1=0.7500000 g2=0.0000000
  241.  
  242.     psect    lo_data
  243.     align    256
  244. a2d
  245. a2m    equ    207-1
  246.     org    x:a2d+a2m
  247.     psect    hf_datax
  248. a2g1    equ    0.7500000
  249. a2g2    equ    0.0000000
  250.  
  251.  
  252. ; storage for "c5" length=2341 modulus=4096 g1=0.3984375 g2=0.5028690
  253.  
  254.     psect    lo_data
  255.     align    4096
  256. c5d
  257. c5m    equ    2341-1
  258.     org    x:c5d+c5m
  259.     psect    hf_datax
  260. c5g1    equ    0.3984375
  261. c5g2    equ    0.5028690
  262.  
  263.  
  264. ; storage for "c6" length=2539 modulus=4096 g1=0.4218750 g2=0.4832767
  265.  
  266.     psect    lo_data
  267.     align    4096
  268. c6d
  269. c6m    equ    2539-1
  270.     org    x:c6d+c6m
  271.     psect    hf_datax
  272. c6g1    equ    0.4218750
  273. c6g2    equ    0.4832767
  274.  
  275.  
  276.     psect    hf_datax
  277. a1r    dc    a1d
  278. a1md    dc    a1m
  279. a1g1d    dc    a1g1
  280. a2r    dc    a2d
  281. a2md    dc    a2m
  282. a2g1d    dc    a2g1
  283.     psect    hf_datay
  284. curaddrp
  285.     dc    curaddr
  286.     psect    hf_datax
  287. constsp    dc    consts
  288. lowstatep
  289.     dc    lowstate
  290.  
  291.     psect    hf_datax1
  292. curaddr
  293.     dc    c1d
  294.     dc    c2d
  295.     dc    c3d
  296.     dc    c4d
  297.     dc    c5d
  298.     dc    c6d
  299.  
  300.     psect    hf_datay1
  301. consts
  302.     dc    c1m
  303.     dc    c1g1
  304.     dc    c1g2
  305.     dc    c2m
  306.     dc    c2g1
  307.     dc    c2g2
  308.     dc    c3m
  309.     dc    c3g1
  310.     dc    c3g2
  311.     dc    c4m
  312.     dc    c4g1
  313.     dc    c4g2
  314.     dc    c5m
  315.     dc    c5g1
  316.     dc    c5g2
  317.     dc    c6m
  318.     dc    c6g1
  319.     dc    c6g2
  320.  
  321.     psect    hf_datax1
  322. lowstate
  323.     dc    0
  324.     dc    0
  325.     dc    0
  326.     dc    0
  327.     dc    0
  328.     dc    0
  329.  
  330. ;;;;;;;;;;;;;;;;;;;;;;;
  331. ; miscellaneous signals
  332. ;;;;;;;;;;;;;;;;;;;;;;;
  333.  
  334.     psect    hf_datax
  335. L_overall
  336.     dc    $7FFFFF
  337. R_overall
  338.     dc    $7FFFFF
  339.  
  340. ;;;;;;;;;;;;;;;;;;;;;;;
  341. ; signal vector
  342. ;;;;;;;;;;;;;;;;;;;;;;;
  343.     psect    hf_datax
  344.     align 8
  345. signal_vector
  346. Lin    dc    0.0
  347. Rin    dc    0.0
  348. Reverb_L
  349.     dc    0.0
  350. Reverb_R    
  351.     dc    0.0
  352.  
  353. Lout
  354.     dc    0
  355. Rout
  356.     dc    0
  357.  
  358.     psect hf_datay
  359. signal_vectorp
  360.     dc    signal_vector
  361. signal_mod
  362.     dc    4-1
  363.  
  364. gain_vectorsp
  365.     dc    gain_vectors
  366. ;;;;;;;;;;;;;;;;;;;;;;;
  367. ; gain matrix
  368. ;;;;;;;;;;;;;;;;;;;;;;;
  369.     psect    hf_datay1
  370. gain_vectors
  371. Reverb_gain_vector
  372. Reverb_Lin    dc 0.5
  373. Reverb_Rin    dc 0.5
  374. Reverb_Reverb_L    dc 0.0
  375. Reverb_Reverb_R    dc 0.0
  376.  
  377. Lout_gain_vector
  378. Lout_Lin    dc 0.0
  379. Lout_Rin    dc 0.0
  380. Lout_Reverb_L    dc ONE
  381. Lout_Reverb_R    dc 0.0
  382.  
  383. Rout_gain_vector
  384. Rout_Lin    dc 0.0
  385. Rout_Rin    dc 0.0
  386. Rout_Reverb_L    dc 0.0
  387. Rout_Reverb_R    dc -1.0
  388.  
  389. ;***************************************************************
  390. ;
  391. ;    init code - call hf_init at first and any time when
  392. ;    parameters change
  393. ;
  394. ;***************************************************************
  395.     psect    lo_code
  396.  
  397. hf_init
  398. ;
  399. ;    clear out the filter delay lines
  400. ;
  401.  
  402.  
  403.  
  404.     move        #c1d,r0
  405.     movec        #c1m,m0
  406.     jsr    clear_line_r0
  407.  
  408.  
  409.     move        #c2d,r0
  410.     movec        #c2m,m0
  411.     jsr    clear_line_r0
  412.  
  413.  
  414.     move        #c3d,r0
  415.     movec        #c3m,m0
  416.     jsr    clear_line_r0
  417.  
  418.  
  419.     move        #c4d,r0
  420.     movec        #c4m,m0
  421.     jsr    clear_line_r0
  422.  
  423.  
  424.     move        #c5d,r0
  425.     movec        #c5m,m0
  426.     jsr    clear_line_r0
  427.  
  428.  
  429.     move        #c6d,r0
  430.     movec        #c6m,m0
  431.     jsr    clear_line_r0
  432.  
  433.  
  434.     move        #a1d,r0
  435.     movec        #a1m,m0
  436.     jsr    clear_line_r0
  437.  
  438.  
  439.     move        #a2d,r0
  440.     movec        #a2m,m0
  441.     jsr    clear_line_r0
  442.  
  443.     jsr    recalc_comb_gains
  444.     rts
  445.  
  446. clear_line_r0
  447.     clr    a
  448.     rep    #0
  449.       move        a,x:(r0)+
  450.     rts
  451.  
  452. ;***************************************************************
  453. ;
  454. ;    sample rate computations
  455. ;
  456. ;    Call hf_comp once per sample.
  457. ;    Globals in_l and in_r should have the left and right
  458. ;    input samples.  When hf_comp returns, out_l and out_r
  459. ;    will be ready.
  460. ;
  461. ;***************************************************************
  462.  
  463. ;
  464. ; fs = 32.552083 kHz
  465. ;
  466.     psect    hf_code
  467.  
  468. hf_comp
  469. ;
  470. ;    copy inputs
  471. ;
  472.     move        x:<in_l,a
  473.     move        a,x:<Lin
  474.     move        x:<in_r,a
  475.     move        a,x:<Rin
  476. ;
  477. ;    compute outputs using matrix multiply
  478. ;
  479. ; [reverb_in out_l out_r] = [gain_vector] * [signal_vector]
  480. ;
  481.     move        y:<signal_vectorp,r0
  482.     movec        y:<signal_mod,m0
  483.     move        y:<gain_vectorsp,r4
  484.     movec        x:<ffff,m4
  485.     move        x:<L_overall,y1        ;and wait for m4
  486.     clr    a    x:(r0)+,x0 y:(r4)+,y0
  487.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  488.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  489.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  490.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  491.     clr    a    a,b            ;b is reverb_in
  492.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  493.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  494.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  495.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  496.     clr    a    a,x1
  497.     mpy    x1,y1,a    x:<R_overall,y1
  498.     clr    a    a,x:<out_l
  499.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  500.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  501.     mac    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  502.     macr    x0,y0,a    x:(r0)+,x0 y:(r4)+,y0
  503.     clr    a    a,x1
  504.     mpy    x1,y1,a
  505.     clr    a    a,x:<out_r
  506. ;
  507. ; r1    lowstate vector
  508. ; m1    -1
  509. ; r4    ptr to modulus,g1,g2 constants
  510. ; m4    -1
  511. ; r5    curaddr ptr
  512. ; m5    -1
  513. ; b    comb out accum
  514. ; x0    scaled comb in
  515. ;
  516. ;
  517. ;    set up reverb input
  518. ;
  519.     clr    b    b,x0            ;get reverb_in
  520.     move        #1.0/16,x1        ;allow 4 bits of headroom
  521.     mpyr    x0,x1,a                ;and 4 bits of noise
  522.     move        a,x0
  523.     move        x:<lowstatep,r1
  524.     movec        x:<ffff,m1
  525.     move        x:<constsp,r4
  526.     movec        m1,m4
  527.     move            y:<curaddrp,r5
  528.     movec        m1,m5
  529. ;
  530. ;    do the six combs
  531. ;
  532.     do    #6,comb_loop
  533.       move        x:(r5),r0        ;r0=curaddr
  534.       movec        y:(r4)+,m0        ;m0=modulus
  535.       move        x:(r1),x1 y:(r4)+,y1    ;x1=lowstate, y1=g1, wait for m0
  536.       move        x:(r0)+,y0        ;y0=delay out
  537.       add    y0,b        y0,a        ;a=delay out
  538.       macr    x1,y1,a        y:(r4)+,y1    ;a=out+g1*lowstate, y1=g2
  539.       clr    a          a,x:(r1)+ a,y0        ;y0=new lowstate
  540.       add    x0,a    r0,x:(r5)+        ;a=in, save ptr
  541.       macr    y0,y1,a                ;a=in+g2*g1*lowstate
  542.       move        a,x:-(r0)        ;store delay in (takes 2 cyc)
  543. comb_loop
  544. ;
  545. ;    scale
  546. ;
  547.     rnd    b    #$15,x0        ;scale by ~1/6
  548.     move        b,y0
  549.     mpyr    x0,y0,b
  550.     move        b,y1        ;save b for right chan
  551. ;
  552. ;    allpass L
  553. ;
  554.     move        x:<a1r,r0
  555.     movec        x:<a1md,m0
  556.     move        x:<a1g1d,x0
  557.     move        x:(r0),x1
  558.     macr    x0,x1,b    x1,a
  559.     move            b,y0
  560.     macr    -x0,y0,a b,x:(r0)+
  561.     asl    a          r0,x:<a1r
  562.     asl    a            ;get rid of the headroom
  563.     asl    a
  564.     asl    a
  565.     move        a,x:<Reverb_L
  566. ;
  567. ;    allpass R
  568. ;
  569.     tfr    y1,b    x:<a2r,r0
  570.     movec        x:<a2md,m0
  571.     neg    b    x:<a2g1d,x0
  572.     move        x:(r0),x1
  573.     macr    x0,x1,b    x1,a
  574.     move            b,y0
  575.     macr    -x0,y0,a b,x:(r0)+
  576.     asl    a    r0,x:<a2r
  577.     asl    a
  578.     asl    a
  579.     asl    a
  580.     move        a,x:<Reverb_R
  581. ;
  582. ;    done
  583. ;
  584.     rts
  585.  
  586.     end
  587.